<template>
	<view class="qr-code">
		<view class="header">
			<text class="title">我的二维码</text>
		</view>
		
		<view class="content">
			<view class="user-info">
				<image class="avatar" :src="userInfo.avatar" mode="aspectFill"></image>
				<view class="user-details">
					<text class="username">{{ userInfo.name }}</text>
					<text class="level">{{ userInfo.level }}</text>
				</view>
			</view>
			
			<view class="qrcode-container">
				<view class="qrcode-card">
					<canvas canvas-id="qrcode" class="qrcode-canvas"></canvas>
					<text class="qrcode-tip">扫一扫上面的二维码，添加我为好友</text>
				</view>
			</view>
			
			<view class="actions">
				<button class="action-btn" @click="saveQrCode">
					<text class="icon">💾</text>
					<text>保存二维码</text>
				</button>
				<button class="action-btn" @click="shareQrCode">
					<text class="icon">📤</text>
					<text>分享二维码</text>
				</button>
			</view>
		</view>
	</view>
</template>

<script setup>
import { ref, onMounted } from 'vue'

const userInfo = ref({
	name: '用户昵称',
	avatar: '/static/muyuhome/headicon.jpg',
	level: '普通会员'
})

onMounted(() => {
	drawQrCode()
})

const drawQrCode = () => {
	// 模拟生成二维码
	const ctx = uni.createCanvasContext('qrcode')
	ctx.setFillStyle('#000000')
	ctx.fillRect(50, 50, 200, 200)
	ctx.setFillStyle('#ffffff')
	ctx.fillRect(60, 60, 180, 180)
	ctx.setFillStyle('#000000')
	ctx.fillRect(70, 70, 160, 160)
	ctx.draw()
}

const saveQrCode = () => {
	uni.showToast({
		title: '二维码已保存到相册',
		icon: 'success'
	})
}

const shareQrCode = () => {
	uni.showActionSheet({
		itemList: ['微信好友', '朋友圈', 'QQ好友'],
		success: (res) => {
			uni.showToast({
				title: '分享成功',
				icon: 'success'
			})
		}
	})
}
</script>

<style scoped>
.qr-code {
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	min-height: 100vh;
}

.header {
	padding: 40rpx 30rpx 20rpx;
	text-align: center;
}

.title {
	font-size: 36rpx;
	font-weight: bold;
	color: white;
}

.content {
	padding: 0 30rpx 40rpx;
}

.user-info {
	display: flex;
	align-items: center;
	background: rgba(255, 255, 255, 0.1);
	backdrop-filter: blur(10px);
	border-radius: 20rpx;
	padding: 30rpx;
	margin-bottom: 40rpx;
}

.avatar {
	width: 120rpx;
	height: 120rpx;
	border-radius: 50%;
	border: 4rpx solid rgba(255, 255, 255, 0.3);
}

.user-details {
	margin-left: 30rpx;
	display: flex;
	flex-direction: column;
}

.username {
	font-size: 32rpx;
	font-weight: bold;
	color: white;
	margin-bottom: 10rpx;
}

.level {
	font-size: 24rpx;
	color: rgba(255, 255, 255, 0.8);
	background: rgba(255, 255, 255, 0.2);
	padding: 8rpx 16rpx;
	border-radius: 20rpx;
	align-self: flex-start;
}

.qrcode-container {
	display: flex;
	justify-content: center;
	margin-bottom: 40rpx;
}

.qrcode-card {
	background: white;
	border-radius: 20rpx;
	padding: 40rpx;
	text-align: center;
	box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.1);
}

.qrcode-canvas {
	width: 300rpx;
	height: 300rpx;
	margin-bottom: 30rpx;
}

.qrcode-tip {
	font-size: 24rpx;
	color: #666;
}

.actions {
	display: flex;
	justify-content: center;
	gap: 40rpx;
}

.action-btn {
	display: flex;
	flex-direction: column;
	align-items: center;
	background: rgba(255, 255, 255, 0.2);
	backdrop-filter: blur(10px);
	border: none;
	border-radius: 20rpx;
	padding: 30rpx;
	color: white;
	font-size: 24rpx;
}

.action-btn .icon {
	font-size: 48rpx;
	margin-bottom: 10rpx;
}
</style>